<?php  
    require("./PHP/Conn.php");

    $tbls = Array(); 
    function procedure_call($pr)
    {  
        require("./PHP/Conn.php");
        $array = Array();
        if (!$conn) 
        {
            $m = oci_error();
            trigger_error(htmlentities($m['message']), E_USER_ERROR);
        } 
        $curs = oci_new_cursor($conn);
        $stid = oci_parse($conn, "begin ".$pr."(:cursorAux); end;");
        //$stid = oci_parse($conn, "begin PRC001(:cursorAux); end;");
        oci_bind_by_name($stid, ":cursorAux", $curs, -1, OCI_B_CURSOR);
        oci_execute($stid);
        oci_execute($curs);  // Execute the REF CURSOR like a normal statement id 
        while ($row = oci_fetch_array($curs, OCI_ASSOC)) 
        {   
            array_push($array, $row);
        } 
        return $array;
    } 
    
    function procedure_call_2args($pr, $var)
    { 
        $array = Array();
        if (!$conn) 
        {
            $m = oci_error();
            trigger_error(htmlentities($m['message']), E_USER_ERROR);
        } 
        $curs = oci_new_cursor($conn);
        $stid = oci_parse($conn, "begin ".$pr."(:cursorAux, ".$var."); end;");
        oci_bind_by_name($stid, ":cursorAux", $curs, -1, OCI_B_CURSOR);
        oci_execute($stid);
        oci_execute($curs);  // Execute the REF CURSOR like a normal statement id 
        $i =0; 
        while ($row = oci_fetch_array($curs, OCI_ASSOC)) 
        {   
            array_push($array, $row);
        } 
        return $array;
    }

    function tablas($tbls)
    {
        $array = procedure_call("TABLA");  
        $tbls_= Array("USERNAME"=>"","DEFAULT_TABLESPACE"=>"","TEMPORARY_TABLESPACE"=>"");
        foreach($array as $val)
        {
           $tbls_["USERNAME"] = $val["USERNAME"];
           $tbls_["DEFAULT_TABLESPACE"] = $val["DEFAULT_TABLESPACE"];
           $tbls_["TEMPORARY_TABLESPACE"] = $val["TEMPORARY_TABLESPACE"]; 
           array_push($tbls,$tbls_);
        }
    }


    function calls()
    {      
        $date = date("Y-m-d H:i:s"); 
        //$array = procedure_call("TABLESPACES"); 
        $array = procedure_call("ROLESSISTEMA"); 
        foreach($array as $val)
        {
            echo implode($val)."</br>";
        }
    } 